package com.androidy;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class contact extends Activity implements OnClickListener{
	ImageView fb, gmail, gplus, linkin;
	Button back;
	boolean is_show_browswer;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.contact);
		TextView header = (TextView)this.findViewById(R.id.header);
		header.setText("Contact Me");
		LinearLayout head_layout = (LinearLayout)this.findViewById(R.id.natvigation);
		back = (Button)this.findViewById(R.id.back);
		back.setText("back");
		head_layout.setBackgroundResource(R.drawable.yellow);
		fb = (ImageView)this.findViewById(R.id.fb);
		gmail = (ImageView)this.findViewById(R.id.gmail);
		gplus = (ImageView)this.findViewById(R.id.gplus);
		linkin = (ImageView)this.findViewById(R.id.linkin);
		fb.setOnClickListener(this);
		gmail.setOnClickListener(this);
		gplus.setOnClickListener(this);
		linkin.setOnClickListener(this);
		back.setOnClickListener(this);
		fb.setVisibility(View.INVISIBLE);
		gmail.setVisibility(View.INVISIBLE);
		gplus.setVisibility(View.INVISIBLE);
		linkin.setVisibility(View.INVISIBLE);
        set_viewlistener(gplus, 0);
        set_viewlistener(gmail, 100);
        set_viewlistener(linkin, 200);
        set_viewlistener(fb, 300);
        is_show_browswer = false;
    }
    
    public void set_viewlistener(View v, long offset){
    	final View x = v;
    	final long off = offset;
    	v.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
            	x.setVisibility(View.VISIBLE);
            	gen_animation(x, off);
            }
        });
    }
        
    public void gen_animation(View v, long shift){
    	Animation am1 = new ScaleAnimation( 0.0f, 1.2f, 0.0f, 1.2f, v.getWidth()/2, v.getHeight()/2 );
	    am1.setDuration( 900 );
	    am1.setStartOffset(shift);
	    am1.setRepeatCount( 0 );
    	Animation am2 = new AlphaAnimation( 0, 1 );
	    am2.setDuration( 1600 );
	    am2.setStartOffset(shift);
	    am2.setRepeatCount( 0 );
    	Animation am3 = new ScaleAnimation( 1.0f, 1/1.2f, 1.0f, 1/1.2f, v.getWidth()/2, v.getHeight()/2 );
	    am3.setDuration( 400 );
	    am3.setStartOffset(shift + 900);
	    am3.setRepeatCount( 0 );
    	Animation am4 = new ScaleAnimation( 1.0f, 1.1f, 1.0f, 1.1f, v.getWidth()/2, v.getHeight()/2 );
	    am4.setDuration( 200 );
	    am4.setStartOffset(shift + 1300);
	    am4.setRepeatCount( 0 );
    	Animation am5 = new ScaleAnimation( 1.0f, 1/1.1f, 1.0f, 1/1.1f, v.getWidth()/2, v.getHeight()/2 );
	    am5.setDuration( 100 );
	    am5.setStartOffset(shift + 1500);
	    am5.setRepeatCount( 0 );
	    
	    AnimationSet am = new AnimationSet( false );
	    am.addAnimation( am1 );
	    am.addAnimation( am2 );
	    am.addAnimation( am3 );
	    am.addAnimation( am4 );
	    am.addAnimation( am5 );
	    
	    v.setAnimation(am);
	    am.startNow();
    }

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (v == fb){
			Intent myIntent = new Intent(Intent.ACTION_VIEW);
			myIntent.setData(Uri.parse("https://www.facebook.com/profile.php?id=556169514"));
			startActivity(myIntent);
		} else if (v == gmail){
			Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
	        emailIntent.setType("text/plain");
	        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"andy0929@gmail.com"});
	        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Contact Andy");
	        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "");
	        this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));	
		} else if (v == gplus){
			Intent myIntent = new Intent(Intent.ACTION_VIEW);
			myIntent.setData(Uri.parse("https://plus.google.com/103917448129162183434/posts"));
			startActivity(myIntent);
		} else if (v == linkin){
			Intent myIntent = new Intent(Intent.ACTION_VIEW);
			myIntent.setData(Uri.parse("http://www.linkedin.com/profile/view?id=162155939"));
			startActivity(myIntent);
		} else if (v == back) {
			this.finish();
		}
	}
}
